package module.service.impl;

import common.bean.SearchPageResult;
import common.bean.SearchParameter;
import module.dao.ServiceDao;
import module.model.ServiceModel;
import module.service.ServiceModelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

@Service
public class ServiceModelServiceImpl implements ServiceModelService{
    @Autowired
    private ServiceDao serviceDao;

    @Transactional
    public SearchPageResult<ServiceModel> getServiceModelListPage(Integer page) {
        SearchParameter searchParameter = new SearchParameter();
        searchParameter.setPageIdx(page);
        searchParameter.setPagination(true);
        return serviceDao.getServiceModelListPage(searchParameter);
    }
    @Transactional
    public ServiceModel saveServiceModel(ServiceModel serviceModel) {
        serviceModel.setCreateDate(new Date());
        serviceDao.save(serviceModel);
        return serviceModel;
    }
    @Transactional
    public ServiceModel updateServiceModel(ServiceModel serviceModel) {
        serviceModel.setLastUpdateTime(new Date());
        return serviceDao.update(serviceModel);
    }
    @Transactional
    public ServiceModel getServiceModelByServiceId(Long serviceId) {
        return serviceDao.load(ServiceModel.class,serviceId);
    }
}
